<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>修改车位</title>
    <link rel="stylesheet" type="text/css" href="layui/css/layui.css">
    <script src="layui/layui.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div class="layui-container" style="margin-top: 20px">
    <div class="layui-row">
        <div class="layui-col-md6 layui-col-md-offset3">
            <form class="layui-form"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
                <input type="hidden" id="cid" th:value="${space.pid}">
                <div class="layui-form-item">
                    <label class="layui-form-label" for="floorNumber">层位数</label>
                    <div class="layui-input-block">
                        <input type="text" id="floorNumber" name="floorNumber" placeholder="层位数" class="layui-input"
                               th:value="${space.floorNumber}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" for="areaCode">区号</label>
                    <div class="layui-input-block">
                        <select id="areaCode" name="areaCode" class="layui-select-disabled" >
                            <option th:selected="${space.areaCode=='A'}">A</option>
                            <option th:selected="${space.areaCode=='B'}">B</option>
                            <option th:selected="${space.areaCode=='C'}">C</option>
                            <option th:selected="${space.areaCode=='D'}">D</option>
<!--                            <option value="0">A</option>-->
<!--                            <option value="1">B</option>-->
<!--                            <option value="2">C</option>-->
<!--                            <option value="3">D</option>-->
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" for="parkingNumber">车位号</label>
                    <div class="layui-input-block">
                        <input type="text" id="parkingNumber" name="parkingNumber" placeholder="车位号" class="layui-input"
                               th:value="${space.parkingNumber}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" for="unitPrice">单价</label>
                    <div class="layui-input-block">
                        <input type="text" id="unitPrice" name="unitPrice" placeholder="单价" class="layui-input"
                               th:value="${space.unitPrice}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" for="remark">备注</label>
                    <div class="layui-input-block">
                        <input type="text" id="remark" name="remark" placeholder="备注" class="layui-input"
                               th:value="${space.remark}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="editSpace">修改</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>

            </form>
        </div>
    </div>
</div>
<script th:inline="javascript">
    layui.use(['layer', 'form', 'laydate'], function () {
        var $ = layui.jquery;
        var form = layui.form;

        form.on('submit(editSpace)', function (obj) {
            //AJAX请求，用到了thymeleaf内敛脚本
            obj.field.pid = [[${space.pid}]];
            console.log("===========", obj)
            $.post("updateSpace", obj.field, function (d) {
                console.log("d=" + d);
                if (d !== 1) {
                    alert("修改失败")
                } else {
                    //关闭弹出层
                    // layer.getFrameIndex(windowName) - 获取特定iframe层的索引
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                }
            }, "json");
            //取消form提交的默认submit行为
            return false;
        });
    })
</script>
</body>
</html>